package encome.work.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import encome.work.dao.Staff;
import encome.work.mapper.StaffMapper;
import encome.work.service.StaffService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class StaffServiceImpl extends ServiceImpl<StaffMapper, Staff> implements StaffService {
    @Resource
    StaffMapper staffMapper;

    @Override
    public boolean isStaff(long staff_user_id) {
        LambdaQueryWrapper<Staff> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Staff::getUser_id,staff_user_id);
        return staffMapper.exists(queryWrapper);
    }

    @Override
    public void add(long user_id) {
        Staff staff = new Staff() {{
            this.setUser_id(user_id);
        }};
        staffMapper.insert(staff);
    }

    @Override
    public void deleteById(long id) {
        staffMapper.deleteById(id);
    }

    @Override
    public void deleteByUserId(long user_id) {
        LambdaQueryWrapper<Staff> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Staff::getUser_id,user_id);
        staffMapper.delete(queryWrapper);
    }

}
